#include "GameScene.h"

GameScene::GameScene(HINSTANCE hInstance, LPWSTR Name, int Mode, int IsFullScreen, int FrameRate) :
AbstractGame(hInstance, Name, Mode, IsFullScreen, FrameRate)
{
	last_time_update = 0;
}

void GameScene::initializeGame()
{
	_game = new GameManagement(_GSTATE_MENU, _d3ddv, _SpriteHandler, Background);
}

GameScene::~GameScene()
{
}

void GameScene::LoadResources(LPDIRECT3DDEVICE9 d3ddv){
	initializeSpriteHandler(d3ddv);
}

void GameScene::initializeSpriteHandler(LPDIRECT3DDEVICE9 d3ddv) {
	D3DXCreateSprite(d3ddv, &_SpriteHandler);
	HRESULT res = D3DXCreateSprite(_d3ddv, &_SpriteHandler);
	Background = CreateSurfaceFromFile(_d3ddv, L"");
	///
	initializeGame();
}

void GameScene::updateGame() {
	_game->update();
}

void GameScene::RenderFrame(LPDIRECT3DDEVICE9 d3ddv, int t) {
	DWORD now = GetTickCount();
	// Background
	d3ddv->StretchRect(
		Background,
		NULL,
		_BackBuffer,
		NULL,
		D3DTEXF_NONE);

	_SpriteHandler->Begin(D3DXSPRITE_ALPHABLEND);
	_game->draw();
	_SpriteHandler->End();
}

void GameScene::ProcessInput(LPDIRECT3DDEVICE9 d3ddv, int t) {
	if (IsKeyDown(DIK_1)) _game->setInput(DIK_1, false);
	if (IsKeyDown(DIK_2)) _game->setInput(DIK_2, false);
	if (IsKeyDown(DIK_3)) _game->setInput(DIK_3, false);

	if (IsKeyDown(DIK_X))
	{
		_game->setInput(DIK_X, false);
	}
	else
	if (IsKeyDown(DIK_BACKSPACE))
	{
		_game->setInput(DIK_BACKSPACE, false);
	}
	else
	if (IsKeyDown(DIK_RIGHT)) {
		_game->setInput(DIK_RIGHT, false);
	}
	else
	if (IsKeyDown(DIK_LEFT)) {
		_game->setInput(DIK_LEFT, false);
	}
	else
	if (IsKeyDown(DIK_Z)) {
		_game->setInput(DIK_Z, true);
				_game->setInput(0, false);
	}
	else
		_game->setInput(0, false);
	
	if (IsKeyDown(DIK_DOWN)) {
		_game->setInput(DIK_DOWN, false);
	}
	if (IsKeyDown(DIK_UP)) {
		_game->setInput(DIK_UP,false);
	}
	if (IsKeyDown(DIK_SPACE)) {
 		_game->setInput(DIK_SPACE, true);
	}
	if (IsKeyDown(DIK_A)) {
		_game->setInput(DIK_A, false);
	}
}
void GameScene::OnKeyDown(int KeyCode) {
	_game->setInput(KeyCode, false);
}


